﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Zhongy
{
    public class ClientPerPool
    {
        private IList<ClientPer> clientPeerLst;


        public ClientPerPool(int capacity)
        {
            clientPeerLst = new List<ClientPer>(capacity);
        }

        public void Enqueue(ClientPer client)
        {
            clientPeerLst.Add(client);
        }

        public ClientPer Dequeue()
        {
            ClientPer result = null;
            result = clientPeerLst[0];
            clientPeerLst.RemoveAt(0);

            return result;
        }

        public void Dequeue(ClientPer client)
        {
            if (clientPeerLst.Contains(client))
            {
                clientPeerLst.Remove(client);
            }
        }

        public IEnumerator<ClientPer> GetEnumerator()
        {
            return clientPeerLst.GetEnumerator();
        }

        public int Count()
        {
            return clientPeerLst.Count;
        }

        public void DealAll(Action<ClientPer,object> action,object arg)
        {
            if (action == null)
                return;

            for (int i = clientPeerLst.Count-1; i >=0 ; i--)
            {
                action(clientPeerLst[i], arg);
            }
        }
    }
}
